const { createWebAPIRequest } = require('../../util/util')

module.exports = [
  {
    /**
    * @api {get} /music/url [获取歌曲url]
    * @apiGroup Music
    * @apiPermission none
    * @apiParam {Number} offset
    * @apiParam {Number} [br=999000]
    */
    url: '/music/url',
    request: (req, res) => {
      const id = req.query.id
      const br = req.query.br || 999000
      const data = {
        ids: [id],
        br: br,
        csrf_token: ''
      }
      const cookie = req.get('Cookie') ? req.get('Cookie') : ''

      createWebAPIRequest(
        'music.163.com',
        '/weapi/song/enhance/player/url',
        'POST',
        data,
        cookie,
        musicReq => {
          res.setHeader('Content-Type', 'application/json')
          res.send(musicReq)
        },
        err => {
          res.status(500).send({err})
        }
      )
    }
  }
]
